package tp.pr1;

public class Room {

	private boolean exit;
	private String description;
	private Room[] rooms= new Room [4];
	
	// constructor
	public Room (boolean exit, String description)
	{
		this.exit = exit;
		this.description = description;
		
		for (int i=0; i<rooms.length;i++)
		{
			rooms[i]=null;
		}
		
	}
	
	//metodo propio
	//devuelve el indice que se usa para el array de direcciones en funcion de la localizacion
	// norte, sur, este u oeste
	
	private int codDirection (Directions dir)
	{
		int result =432;
		
		switch (dir)
		{
			case NORTH: 
				result=0; 
				break;
			case EAST: 
				result=1;
				break;
			case SOUTH: 
				result=2;
				break;
			case WEST: 
				result=3;
				break;
			case UNKNOWN:
				result=4;
				break;				
		}
		
		return result;
		
	}

	public void setRoom(Directions dir,Room room)
	{
		/*switch (dir)
		{
			case NORTH: 
				rooms[0]=room; 
				break;
			case EAST: 
				rooms[1]=room; 
				break;
			case SOUTH: 
				rooms[2]=room; 
				break;
			case WEST: 
				rooms[3]=room; 
				break;			
		}*/
		
		int indice = this.codDirection(dir);
		if (indice != 4) this.rooms[indice]=room;
	}
	
	public boolean isExit()
	{
		boolean salida = this.exit;
		
		return salida;		
	} 
	
	public String getDescription()
	{
		String descripcion = this.description;
		
		return descripcion;
	}
	
	public Room getNextRoom(Directions dir)
	{
		Room habitacion=null;
		/*switch (dir)
		{
			case NORTH: 
				habitacion=this.rooms[0]; 
				break;
			case EAST: 
				habitacion=this.rooms[1];
				break;
			case SOUTH: 
				habitacion=this.rooms[2]; 
				break;
			case WEST: 
				habitacion=this.rooms[3]; 
				break;
		}*/
		
		int indice =this.codDirection(dir);
		
		if (indice != 4 )habitacion =this.rooms[indice];
		
		return habitacion;
	}

}
